/*****************************************************************************
* $Workfile:: common.h                                                      $
* $Revision:: 1                                                             $
* $JustDate::  1/27/12                                                      $
* $History:: common.h                                                       $
*
* *****************  Version 1  *****************
* User: Enrique.torrano Date: 1/27/12    Time: 4:28p
* Created in $/Projects/Dingli/Scissors/Software-New-Make/dingli_ecu
*
* *****************  Version 1  *****************
* User: Gary.flodin  Date: 4/05/10    Time: 4:45p
* Created in $/Projects/Dingli/Scissors/Software/hybrid_ecu
* Rev 01
*
* *****************  Version 1  *****************
* User: Vmnuskin     Date: 11/30/04   Time: 9:54a
* Created in $/Projects/Genie Slab Gen V/software/genie_v_ecu
*
* *****************  Version 1  *****************
* User: Vmnuskin     Date: 11/05/04   Time: 5:08p
* Created in $/Projects/Genie Slab Gen V/software/GENIE_V_ECU
*
* *****************  Version 1  *****************
* User: Vmnuskin     Date: 11/05/04   Time: 5:06p
* Created in $/Projects/Genie Slab Gen V/software/SOFTWARE/genie_v_ecu
*
* *****************  Version 2  *****************
* User: Vmnuskin     Date: 10/28/04   Time: 8:55a
* Updated in $/Projects/Genie Slab Gen V/software/genie_v_pc
*
* *****************  Version 1  *****************
* User: Vmnuskin     Date: 10/22/04   Time: 12:01p
* Created in $/Projects/Genie Slab Gen V/SOFTWARE/genie_v_pc
*
* *****************  Version 1  *****************
* User: Vmnuskin     Date: 8/18/04    Time: 11:04a
* Created in $/Projects/Upright Platforms - Universal Platform Controller/sof
*****************************************************************************/

#ifndef COMMON_H
#define COMMON_H

//#include  <machine.h>
#include    "r_cg_adc.h"
#include    "r_cg_port.h"
#include    "r_cg_serial.h"
#include    "r_cg_timer.h"
#include    "r_cg_wdt.h"
#include    "r_cg_macrodriver.h"
#include    "r_cg_can.h"

typedef unsigned char      BOOL;
typedef int           INT16;
typedef unsigned int  UINT16;
typedef unsigned long UINT32;
typedef long int      INT32;
typedef unsigned char UINT8;
typedef signed char   INT8;

typedef void (*pf_t)(void);


#define TRUE  1
#define FALSE 0

#define INTERRUPTS_ENABLE  EI()
#define INTERRUPTS_DISABLE DI()

// Code Image Checksum Address must match Labview programmer settings.
// the main code must not overwrite the last 128 bytes of the flash.
//#define CodeImageSizeAddress     0x7F80l
//#define CodeImageChecksumAddress 0x7F84l

// Aplication Start Address must match INTVECTORS section of the main code.
#define ApplicationStartAddress  0x40000L

// Aplacation SW Rev Address must match  REVISON seciton of the main code

// Boot SW Rev Address must match REVISON seciton of the boot code
#define BootSWRevAddress    0x3000

#define FlashSizeInBytes    0x20000L

// the magic numbers for self resets
#define BOOT_MODE_MAGIC  0x00FFAA55L
#define APP_MODE_MAGIC   0xFACE1234L
#define APP_MODE_LABVIEW 0x51AF8EC3L


#define IMAGE_MAGIC_ECU         0xab1df56e
#define IMAGE_MAGIC_PLATFORM    0x38d7b91a
#define IMAGE_MAGIC_HYBRID_ECU          0x9AF1E2D3
#define IMAGE_MAGIC_HYBRID_PLATFORM     0x3D2E1FA9

#define IMAGE_DESCRIPTOR_BLOCK_SIZE 128

struct image_hd
{
   UINT16  wHeaderSum;           // sum of all bytes
   UINT32  dwMagic;
   UINT32  dwImageLength;         // calculated by genie.exe
   UINT16  wImageSum;            // make it 16 bit crc
};

struct image_descr
{
   struct image_hd header;
   char szName[ IMAGE_DESCRIPTOR_BLOCK_SIZE  - sizeof(struct image_hd)];
};

extern const struct image_descr IMAGE_Descr;
extern UINT32 BootFlag;
extern const UINT8 au8BootRevision[];

#endif  // COMMON_H
